/*
 *  bandpIncludes.h
 *  Ball and Plate
 *
 *  Created by Kenn Sebesta on 2008-04-08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef BANDPINCLUDES
#define BANDPINCLUDES

#define DEBUG 0         // Turns on debugger and sets level

#define CAMWIRE         // Options are CAMWIRE or OPENCV. If you are not using a DC1394 camera, disable this!
#define PLATFORM_LINUX  // Options are PLATFORM_MAC, PLATFORM_LINUX, PLATFORM_WINDOWS


#ifdef PLATFORM_MAC
#include <OpenCv/OpenCv.h>
#else
#include <cv.h>
#include <highgui.h>
#endif

#ifdef CAMWIRE
#include "camwireFunctions.h"
#include <camwire/camwire.h>
#endif

// Camera object
typedef struct CamHandle {
    union {
        CvCapture *opencv;
        #ifdef CAMWIRE
        Camwire_handle camwire;
        #endif
    }; /* camera handle pointers */
    
};

// Table object
typedef struct SystemDims {
    CvMat *actuator_0;
    CvMat *actuator_1;
    CvMat *actuator_2;
    CvMat *tableCenter;
    CvMat *tableDims;
    double cameraHeight;
    double ballDia;
    int numActuators;
};

// Mask object
typedef struct MaskObject {
    char name[20];
    
    float dia;
    int diaPix;
    int found;
    CvMat *state;
    
    union{
        CvMat *points;
        IplImage *image;
    }; /* object mask coordinates, either in n X 3 matrix or diaPix X diaPix image form */
    
    CvMat *pixCoordsMat;
    float pixCoords[2];
    /*    pixCoordsMat=cvCreateMatHeader( 2, 1, CV_32F );
    cvInitMatHeader( pixCoordsMat, 2, 1, CV_32F, pixCoords ); */
    
    CvMat *spatialCoordsMat;
    float spatialCoords[3];
/*    spatialCoordsMat=cvCreateMatHeader( 3, 1, CV_32F );
    cvInitMatHeader( spatialCoordsMat, 3, 1, CV_32F, spatialCoords ); 
*/
    
    CvMat *rotationMat;
};

// Setpoint object
typedef struct SetPoint {
    char pathName[100];
    double ballSpeed;
    double ballSpeedR;
    double pathRadius;
    int pathNum;
    int trajectoryStep;
//    enum pathValue {stabilize, circle, ellipse, spiral, figure_eight}; //NOT YET USED FOR ANYTHING
    
    CvMat *errMat;
//    double bob;
    CvMat *integrationPositionErr;
    CvMat *integrationVelocityErr;
    double integrationPositionGain;
    double integrationVelocityGain;
    CvMat *setPoint;
    CvMat *setPointR;
    CvMat *tableCenter;
};

// Image analysis object
typedef struct ImageSet {
    
    IplImage *cropImage;
    IplImage *grayImage;
    IplImage *bwImage;
    IplImage *edgeImage;
    IplImage *ballMask; //NOT CURRENTLY USED
    CvMat *convMat;
    
    CvRect cropRect;
};

// Image analysis parameters object
typedef struct ImageAnalysisParams {  
    int isDifferent;        //Have the image dimensions changed since last loop? If so, this goes to 1.
    int binaryThresh;
    int cannyThreshHigh;    // Thresholds for the Canny edge detection.
    int cannyThreshLow;     // LOW and HIGH actually have little meaning as the 
                            // Canny will internally swap them if HIGH is lower
                            // than LOW.
    
    float decimate;
    double latency;
    double received_time;
    double trigger_time;
    struct timespec timestamp; //A convenient place to store the timestamp data
    struct timeval tv_received;
};

#endif
